package com.sykj.why.mongo.service.impl;

import com.sykj.why.exception.WhyException;
import com.sykj.why.mongo.dao.BasicDao;

import com.sykj.why.mongo.document.BaseDocument;
import com.sykj.why.mongo.enums.exception.ResultEnum;
import com.sykj.why.mongo.service.BasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author Mr.will
 */
@Service("basicService")
public class BasicServiceImpl<T extends BaseDocument> implements BasicService<T> {
    @Autowired
    private BasicDao<T> basicDao;

    @Override
    public void save(T entity) {
        basicDao.save(entity);
    }

    @Override
    public void saveOrupdate(T entity) {
        basicDao.saveOrupdate(entity);
    }

    @Override
    public void remove(T entity) {
        basicDao.remove(entity);

    }

    @Override
    public void delete(T entity) {
        basicDao.delete(entity);

    }

    @SuppressWarnings("rawtypes")
    @Override
    public List<T> findAll(Class cls) {
        return basicDao.findAll(cls);
    }

    @Override
    public List<T> findAll(Query query, Class<T> t) {
        return basicDao.findAll(query, t);
    }


    @Override
    public List<T> findAll(Class<T> t, boolean removed) {
        return basicDao.findAll(t, removed);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public T get(Class cls, String id, boolean removed) {
        return basicDao.get(cls, id, removed);
    }

    @Override
    public T get(Class cls, String id) {
        return basicDao.get(cls, id);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public T get(String fieldName, Object getValue, Class cls, boolean removed) {
        return basicDao.get(fieldName, getValue, cls, removed);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public T get(String fieldName1, Object getValue1, String fieldName2, Object getValue2, Class cls, boolean removed) {
        return basicDao.get(fieldName1, getValue1, fieldName2, getValue2, cls, removed);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public boolean update(String updatename, Object updatevalue, String id, Class entity) {
        return basicDao.update(updatename, updatevalue, id, entity);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public boolean updateAll(String updatename, Object updatevalue, String updateId, String id, Class entity) {
        return basicDao.updateAll(updatename, updatevalue, updateId, id, entity);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public long count(String fieldName, Object selRemoved, Class entity) {
        return basicDao.count(fieldName, selRemoved, entity);
    }

    @Override
    public T findOne(Query query, Class<T> t) {
        return basicDao.findOne(query,t);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public long count(String fieldName, Object selRemoved, boolean removed, Class entity) {
        return basicDao.count(fieldName, selRemoved, removed, entity);
    }

    @SuppressWarnings("rawtypes")
    @Override
    public long count(String fieldName1, Object selRemoved1, String fieldName2, Object selRemoved2, boolean removed, Class entity) {
        return basicDao.count(fieldName1, selRemoved1, fieldName2, selRemoved2, removed, entity);
    }

    @Override
    public List<T> findByPage(Query query, int currentPage, int lineSize, Class<T> t) {
        return basicDao.findByPage(query, currentPage, lineSize, t);
    }

    @Override
    public List<T> findDistinctAll(String collection, String key) {
        // TODO Auto-generated method stub
        return basicDao.findDistinctAll(collection, key);
    }

    @Override
    public int getPageSize(int totalCount, int lineSize) {
        return basicDao.getPageSize(totalCount, lineSize);
    }

    @Override
    public long count(Query query, Class<T> entity) {
        // TODO Auto-generated method stub
        return basicDao.count(query, entity);
    }






    /**
     * 验证是否拿到机构Id
     *
     * @param orgId
     * @return
     */
    /*@Override
    public void verifyOrgId(String orgId) {
        if(orgId==null){
            throw new WhyException(ResultEnum.ORGANIZATIONID_NULL);
        }
    }*/


}
